const {mysql} = require('../qcloud')

async function hotSearch (ctx) {
    const hotSearch = await mysql('nideshop_keywords').distinct('keyword').column('keyword', 'is_hot').limit(5).select()

    ctx.state.data = {
        hotSearch
    }
}

async function searchGoods (ctx) {
    const { keyword } = ctx.query
    
    const keywords = await mysql('nideshop_goods')
                            .where('name', 'like', `%${keyword}%`)
                            .limit(15)
                            .select('name')
    ctx.state.data = {
        keywords
    }
}

module.exports = {
    hotSearch,
    searchGoods
}
